package com.baizhi.cmfzmanager.controller;

import com.baizhi.cmfzmanager.entity.UserDTO;
import com.baizhi.cmfzmanager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/getUsers")
    public Map getUsers(int page,int rows){
        return userService.getUsers(page,rows);
    }
    @RequestMapping("/getSexData")
    public List<UserDTO> getSexData(){
        return userService.getSexData();
    }
    @RequestMapping("/getProvinceData")
    public List<Map> getProvinceData(){
        return userService.getProvinceData();
    }

    @RequestMapping("/getRegistData")
    public List<UserDTO> getRegistData(){
        return userService.getRegistData();
    }

    @RequestMapping("/getChina")
    public List<Map> getChina(){

        return userService.getProvinceData();
    }

    @RequestMapping("/getThreeByOne")
    public Map getThreeByOne(){

        long start = System.currentTimeMillis();
        Map three = userService.getThreeByOne();

        long end = System.currentTimeMillis();
        long times=start-end;
        System.out.println(times+"ms");
        return three;

    }


    @RequestMapping("/getThreeByMany")
    public Map getThreeByMany() throws InterruptedException {

        long start = System.currentTimeMillis();
        Map three = userService.getThreeByMany();

        long end = System.currentTimeMillis();
        long times=start-end;
        System.out.println(times+"ms");
        return three;

    }

    @RequestMapping("/getThreeByFuture")
    public Map getThreeByFuture() throws Exception {
        long start = System.currentTimeMillis();
        Map three = userService.getThreeByFuture();

        long end = System.currentTimeMillis();
        long times=start-end;
        System.out.println(times+"ms");
        return three;
    }
    @RequestMapping("/freeze")
    public String freeze(int id){
        try {
            userService.freeze(id);
            return "冻结成功！！！";
        } catch (Exception e) {
            e.printStackTrace();
            return "冻结失败！！！";
        }
    }

}
